<!DOCTYPE html>
<html>
<?php $this->load->view('admin/public/header.html');?>
<style>
	. space{padding:10px;}

</style>
<body class="childrenBody">
<form class="layui-form layui-row layui-col-space20" lay-filter="expert_form">
	<div class="layui-col-md6 layui-col-xs12 ">
		<div class="layui-row layui-col-space10">
			<div class="layui-col-md12 layui-col-xs7">
				<div class="layui-form-item magt3">
					<div class="layui-row layui-col-space10">
						<div class="layui-col-md6 layui-col-xs6">
							<label class="layui-form-label">项目封面</label>
							<div class="layui-upload-list thumbBox posterBox mag0 magt3">
								<img class="layui-upload-img thumbImg posterimg"  src="">
								<input type="hidden" class="poster" name="poster">
							</div>
						</div>						
					</div>
				</div>
				<div class="layui-form-item magt3">
					<label class="layui-form-label">项目标题</label>
					<input type="hidden" class="projectId" name="projectId" value="">
					<div class="layui-input-block">
						<input type="text" class="layui-input name" name="title" lay-verify="required" placeholder="请输入项目标题">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">购买须知</label>
					<div class="layui-input-block">
						<textarea placeholder="请输入购买须知" name="tips"  lay-verify="required" class="layui-textarea brief"></textarea>
					</div>
				</div>
			</div>
		</div>
		
		<div class="layui-form-item magb0">
			<label class="layui-form-label">项目详情</label>
			<div class="layui-input-block">
				<textarea class="layui-textarea layui-hide" name="content" lay-verify="content" id="content"></textarea>
			</div>
		</div>
	</div>
	<div class="layui-col-md6 layui-col-xs12 ">
		<blockquote class="layui-elem-quote title"><i class="seraph icon-caidan"></i> 项目分类</blockquote>
		<div class="border category">
			<div class="layui-form-item">
				<select name="typeId" lay-verify="required" lay-search>
				  <option value="">请选择分类</option>
				  <?php foreach($type as $key=>$val):?>
				  	<option value="<?php echo $val['typeId']?>"><?php echo $val['typeName']?> </option>
				  <?php endforeach;?>
				</select>
			</div>
		</div>
		<br>
				
		<blockquote class="layui-elem-quote title"><i class="seraph icon-caidan"></i> 项目功效</blockquote>
		<div class="border category">
			<div class="layui-form-item">
				<input type="text" class="layui-input name" name="effect" lay-verify="required" placeholder="多个功能以|隔开,如:养生|促进睡眠">
			</div>
		</div>
		<br>
		
		<blockquote class="layui-elem-quote title"><i class="seraph icon-caidan"></i> 项目价格</blockquote>
		<div class="border category">
			<div class="layui-form-item">
				<input type="text" class="layui-input name" name="price" lay-verify="required" placeholder="请输入项目价格">
			</div>
		</div>
		<br>
		
		<blockquote class="layui-elem-quote title"><i class="seraph icon-caidan"></i> 项目服务时长(分钟)</blockquote>
		<div class="border category">
			<div class="layui-form-item">
				<input type="text" class="layui-input name" name="duration" lay-verify="required" placeholder="请输入项目服务时长">
			</div>
		</div>
		<br>
		
		<blockquote class="layui-elem-quote title"><i class="seraph icon-caidan"></i> 提供的服务</blockquote>
		<div class="border category">
			<div class="layui-form-item">
				<?php foreach($service as $key=>$val):?>
					<input type="checkbox" name="serviceTypeIds[]" class="tags"  lay-verify="required" title="<?php echo $val['typeName']?>" value="<?php echo $val['typeId']?>">
				<?php endforeach;?>
			</div>
		</div>
		<br>
		
		
		<!-- <div class="">
			<div class="layui-right">
					<a class="layui-btn layui-btn-sm" lay-filter="addNews" lay-submit><i class="layui-icon">&#xe609;</i>发布</a>
			</div>
		</div> -->
	</div>
</form>
<script type="text/javascript">
var path='/public/appeditor/';
layui.config({
	base : path
}).extend({
	"appeditor" : "appeditor"
})
layui.use(['form','layer','layedit','laydate','upload',],function(){
	
	
    var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
        laypage = layui.laypage,
        upload = layui.upload,
        layedit = layui.layedit,
        laydate = layui.laydate,
        $ = layui.jquery;


    
    var layerindex;		//弹层句柄
    //上传缩略图
    upload.render({
        elem: '.posterBox',
        //multiple:true,
        url: '<?php echo site_url("upload/upload")?>',
        before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
        	layerindex=layer.load(); //上传loading
        },
        done: function(res, index, upload){
        	console.log(1);
        	layer.close(layerindex);
            if(res.code==200){
            	layer.msg('上传成功');
            	var url=res.content.url
            	var src='<?php echo IMAGEHOST?>'+url;
            	$('.posterimg').attr('src',src);
                $('.thumbBox').css("background","#fff"); 
                $(".poster").val(url);
            }else{
            	layer.msg('上传失败');
            }
        }
    });
    
    upload.render({
        elem: '.bannerBox',
        //multiple:true,
        url: '<?php echo site_url("upload/upload")?>',
        before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
        	layerindex=layer.load(); //上传loading
        },
        done: function(res, index, upload){
        	console.log(2);
        	layer.close(layerindex);
            if(res.code==200){
            	layer.msg('上传成功');
            	var url=res.content.url
            	var src='<?php echo IMAGEHOST?>'+url;
            	$('.bannerimg').attr('src',src);
                $('.thumbBox').css("background","#fff"); 
                $(".banner").val(url);
            }else{
            	layer.msg('上传失败');
            }
        }
    });

    //格式化时间
    function filterTime(val){
        if(val < 10){
            return "0" + val;
        }else{
            return val;
        }
    }
    
    

	
    
    form.on("submit(addNews)",function(data){
    	//用于同步编辑器内容到textarea
        var tempcontent=layedit.getContent(editIndex);
    	
    	data.field.content=tempcontent;
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        
        $.ajax({
        	type:'post',
        	data:data.field,
        	url:'action',
        	dataType: "json", 
        	success:function(res){
        		//console.log(res.code);return;
        		if(res.code==200){
        			top.layer.close(index);
                    top.layer.msg("添加成功！");
                    layer.closeAll("iframe");
                    //刷新父页面
                    parent.location.reload();
        		}else{
        			top.layer.close(index);
                    top.layer.msg("添加失败！");
        		}
        	},
        	fail:function(){
        		top.layer.close(index);
                top.layer.msg("添加失败！");
        	}
        })        
        
    })

    
    
    //创建一个编辑器
    var editIndex = layedit.build('content',{
        height : 535,
        uploadImage : {
            url : "<?php echo site_url('upload/editUpload')?>"
        }
    });
	//用于同步编辑器内容到textarea
    layedit.sync(editIndex);

})
</script>
</body>
</html>